using System.Collections;
using System.ComponentModel;
using System.IO;
using Send2Sharepoint.Common;

namespace Send2Sharepoint.Explorer
{
    public class DirectoryItem : WorkItem
    {
        public ArrayList SelectedItems { get; private set; }

        public DirectoryItem(string folderName)
        {
            var directoryInfo = new DirectoryInfo(folderName);
            var files = directoryInfo.GetFiles("*.*");
            foreach (var file in files)
                SelectedItems.Add(file);
        }

        internal override void Upload(BackgroundWorker worker, DoWorkEventArgs e)
        {
            var totalItems = SelectedItems.Count;
            var count = 1;
            var lastPercentDone = 0;
            foreach (var file in SelectedItems)
            {
                //Do file Import
                var percentDone = (count / totalItems) * 100;
                if (percentDone > lastPercentDone)
                {
                    worker.ReportProgress(percentDone);
                    lastPercentDone = percentDone;
                }
                count++;
            }
        }

    }
}